<!-- 网站订单修改视图 -->
<style type="text/css">
#stock-order,#stock-info {
	margin-top: 10px;
}
#scanForm {
	padding-bottom: 5px;
}
#outStock {
	margin-top: 5px;
}
.message {
	margin-bottom: 10px;
}
a {
	cursor: pointer;
}
.after-edit.form-inline input {
	width: 88px;
	padding: 6px;
	margin-bottom: 5px;
}
.delete-sn,.delete-sn:hover {
	color: #636e7b;
	margin-left: 5px;
	font-size: 11px;
}
.modal .modal-dialog {
	margin-top: 128px;
}
.size .after-edit select {
	padding: 5px;
	margin-bottom: 5px;
	width: 88px;
}
.message a {
	color: #c7254e;
}
</style>
<div class="pageheader">
	<h2>
		<i class="fa fa-pencil-square"></i>日志管理
	</h2>
	<div class="breadcrumb-wrapper">
		<span class="label">你所在的位置：</span>
		<ol class="breadcrumb">
			<li><a href="/index">ERP管理系统</a></li>
			<li>日志管理</li>
			<li>网站订单日志</li>
			<li class="active">订单修改</li>
		</ol>
	</div>
</div>
<div class="contentpanel">
<div class="main">
    <div class="table-responsive">
        <div class="message">
            <label>订单信息：</label>
            <a target="_blank" href="<?php echo $this->url(array('controller'=>'log','action'=>'index','oid' =>$this->id,'site'=>$this->site),null,true)?>"><code>订单号为<?php echo $this->id;?>,来自网站<?php echo $this->site;?></code></a>
        </div>
        <div class="clearfix">
            <div class="btn-group">
                <button id="edit-new" class="btn btn-default">新增
                    <i class="fa fa-plus"></i>
                </button>
            </div>
            <div class="btn-group pull-right">
                <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">工具
                    <i class="fa fa-angle-down"></i>
                </button>
                <ul class="dropdown-menu pull-right">
                    <li><a href="#">打印</a></li>
                    <li><a href="#">保存PDF</a></li>
                    <li><a href="#">导出Excel</a></li>
                </ul>
            </div>
        </div>
        <form method="post" action="/log/domodify">
            <input hidden="hidden" name="o_id" value="<?php echo $this->id;?>">
            <input hidden="hidden" name="site" value="<?php echo $this->site;?>">
            <table id="order-log" class="table table-bordered table-hover table-info">
                <thead>
                    <tr>
                        <th>SKU</th>
                        <th>产品名称</th>
                        <th>尺码和数量</th>
                        <th>下单时间</th>
                        <th>状态</th>
                        <th>编辑</th>
                    </tr>
                </thead>
                <tbody>
                <?php 
                if ($this->logList){ 
                    foreach ($this->logList as $v){
                ?>
                <tr id="<?php echo $v['sku'];?>">
                    <td class="sku">
                        <?php echo $v['sku'];?><input type="text" hidden="hidden" value="<?php echo $v['sku'];?>" name="o_sku[]">
                    </td>
                    <td><?php echo $v['title'];?></td>
                    <td class="size">
                        <div class="after-save">
                        <?php  
                        foreach(json_decode($v['info'], true) as $_v){
                            echo '尺码: ' . $_v[0] . ', 数量: ' . stripslashes($_v[1]) . '<br/>';
                        }
                        ?>
                        </div>
                        <div class="lack">
                        <?php 
                        foreach (json_decode($v['lack'],true) as $vl){
                        	if(($vl[1]>0) && $v['statu']){
                        		echo '<p style="display:inline;" class="text-danger">缺:'.$vl[0].'/'.$vl[1].'&nbsp;&nbsp;</p>';
                        		echo '<input class="size_num_'.$vl[0].'" name="onum_'.$v['sku'].'_'.$vl[0].'" type="text" hidden="hidden" value="'.$vl[1].'">';
                        		echo '<input class="check_num_'.$vl[0].'" name="cnum_'.$v['sku'].'_'.$vl[0].'" type="text" hidden="hidden" value="0">';
                        	}else{
                        		echo '<input class="size_num_'.$vl[0].'" name="onum_'.$v['sku'].'_'.$vl[0].'" type="text" hidden="hidden" value="'.$vl[1].'">';
                        		echo '<input class="check_num_'.$vl[0].'" name="cnum_'.$v['sku'].'_'.$vl[0].'" type="text" hidden="hidden" value="0">';
                        	}
                        }
                        ?>
                        </div>
                        <div class="after-edit form-inline hidden">
                        <?php  
                        
                        foreach(json_decode($v['info'], true) as $_v2){
                            //echo '<div>尺码：<input name="'.$v['sku'].'-size[]" class="form-control small" type="text" value="'.$_v2[0].'">';
                            $str = '<div>尺码：<select class="form-control" name="'.$v['sku'].'-size[]">';
                            foreach (json_decode($v['size']) as $siv){
                            	if($_v2[0] == $siv){
                            	    $str = $str.'<option selected="selected" value="'.$siv.'">'.$siv.'</option>';
                            	}else{
                            	    $str = $str.'<option value="'.$siv.'">'.$siv.'</option>';
                            	}
                            }
                            $str = $str.'</select>';
                            echo $str;
                            echo '&nbsp;&nbsp;&nbsp;&nbsp;数量：<input name="'.$v['sku'].'-num[]" class="form-control small" type="text" value="'.stripslashes($_v2[1]).'">' . '<a class="delete-sn">删除</a></div>';
                        }
                        ?>
                        </div>
				    </td>
				    <td><?php echo $v['add_time']; ?></td>
				    <td>
				        <?php
				        switch ($v['statu'])
				        {
				        	case 1:
				        		echo '<span class="status label label-danger">分拣中、缺货中</span>';
				        		break;
				        	case 2:
				        		echo '<span class="status label label-info">分拣完、未处理</span>';
				        		break;
				        	case 3:
				        		echo '<span class="status label label-primary">分拣完、处理中</span>';
				        		break;
				        	case 4:
				        		echo '<span class="status label label-success">分拣完、处理完</span>';
				        		break;
				        	default:
				        		echo '<span class="status label label-warning">未分拣、未处理</span>';
				        }
				        ?>
				    </td>
				    <td><a class="edit">修改</a><a class="save hidden">确认</a><br/><a class="add-size hidden">加码</a></td>
			    </tr>
			    <?php
                    }
                }
		    	?> 
                </tbody>
            </table>
            <input class="btn btn-primary" type="submit" value="保存">
        </form>
    </div>
</div>
</div>
<div class="modal" style="display: none; padding-right: 17px;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div id="add-sku" class="text-center">
                    <div class="input-group">
                        <input class="form-control" type="text" placeholder="请输入新增的SKU">
                        <span class="input-group-btn"><button class="btn btn-default" type="button">确定</button></span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="in"></div>
<script type="text/javascript">
$(document).ready(function(){
	$('.edit').live('click',function(){
		var sku = $(this).parent('td').parent('tr').attr('id');
		$('#'+sku+' .after-save').addClass('hidden');
		$('#'+sku+' .edit').addClass('hidden');
		$('#'+sku+' .after-edit').removeClass('hidden');
		$('#'+sku+' .save').removeClass('hidden');
		$('#'+sku+' .add-size').removeClass('hidden');
	});
	$('.save').live('click',function(){
		var sku = $(this).parent('td').parent('tr').attr('id');
		var str = '';
		$('#'+sku+' .after-edit select[name="'+sku+'-size[]"]').each(function (i) {
			str = str+'尺码：'+$(this).val()+'，数量：'+$('#'+sku+' .after-edit input[name="'+sku+'-num[]"]:eq('+i+')').val()+'<br>';
		});
		$('#'+sku+' .after-save').html(str);
		$('#'+sku+' .after-save').removeClass('hidden');
		$('#'+sku+' .edit').removeClass('hidden');
		$('#'+sku+' .after-edit').addClass('hidden');
		$('#'+sku+' .save').addClass('hidden');
		$('#'+sku+' .add-size').addClass('hidden');
	});
	$('.add-size').live('click',function(){
		var sku = $(this).parent('td').parent('tr').attr('id');
		$('#'+sku+' .after-edit').append($('#'+sku+' .after-edit div:eq(0)').clone(true));
	});

	$('.delete-sn').live('click',function(){
		var sku = $(this).parent('div').parent('div').parent('td').parent('tr').attr('id');
		var len = $('#'+sku+' .after-edit div').length;
		$(this).parent('div').remove();
		if(len == 1){
			$('#'+sku).remove();
		}
	});

	$('#edit-new').click(function(){
		$(".modal").show();
		$(".in").addClass("modal-backdrop");
	});
	$('#add-sku .btn').click(function(){
		var sku = $('#add-sku input').val();
		sku = $.trim(sku);//去掉空格
		$(".modal").hide();
		$(".in").removeClass("modal-backdrop");
		if(sku == ''){
			$('#add-sku input').val('');
		}else{
			$.post("/log/modifyadd", {n_sku:sku},
				function(data){
				    if(data.flag == 'success'){
					    $("tbody").append(data.content);
				    }
			    },'json'
		    );
		}
	});
})
</script>